<fieldset id="fd1" style="width:80%;margin:5px;">
	<legend><span>客户信息查询</span></legend>
	<div class="fieldset-body">
		<table class="form-table" border="0" cellpadding="1" cellspacing="2">
			<tr>
				<!--  
				<td class="form-label" style="width:80px;">顾客类型:</td>
				<td style="width:150px"><input id="types" class="mini-combobox" textField="name" valueField="id" data="JS.CONST[1]" allowInput="true" style="width:100%;" /></td>
				-->
				<td class="form-label" style="width:80px;">所在区域：</td>
				<td style="width:150px"><input id="area" expandOnLoad="true" class="mini-treeselect" url="/common/area" multiSelect="false" textField="name" valueField="id" parentField="parent" checkRecursive="true" showFolderCheckBox="true" style="width:150px;" onenter="onKeyEnter"/></td>
				<td class="form-label" style="width:80px;">登录账户:</td>
				<td style="width:150px"><input id="user" class="mini-textbox" emptyText="请输入登录账户" style="width:100%;"/></td>
				<td class="form-label" style="width:80px;">顾客昵称:</td>
				<td style="width:150px"><input id="name" class="mini-textbox" emptyText="请输入昵称" style="width:100%;"/></td>
				<td style="width:150px"><a class="mini-button" id="search" iconCls="icon-search">查询...</a></td>
			</tr>
		</table>
	</div>
</fieldset>
<div class="mini-toolbar" style="padding:0px;margin:6px 0px 0px 0px;border-bottom:0;width:100%;">
	<table style="width:100%;">
		<tr>
			<td style="width:100%;">
				<a class="mini-button" iconCls="icon-ok" id="buttonStart" plain="true">启用</a>
				<a class="mini-button" iconCls="icon-lock" id="buttonEnd" plain="true">禁用</a>
				<span class="separator"></span>
				<a class="mini-button" iconCls="icon-download" id="buttonDown" plain="true">降级为潜在顾客</a>
				<span class="separator"></span>
				<a class="mini-button" iconCls="icon-tip" id="buttonUp" plain="true">把客户同步到积分商城</a>
				<span class="separator"></span>
				<a class="mini-button" iconCls="icon-search" onClick="CustomerInfo('id')" plain="true">查看顾客详情</a>
				<span class="separator"></span>
				<a class="mini-button" iconCls="icon-filter" id="buttonReload" plain="true">重置密码(密码：888888)</a>
			</td>
		</tr>
	</table>
</div>
<div id="grid1" class="mini-datagrid" allowAlternating="true"  idField="id" pageSize="20" style="width:100%;height:80%;" url="/customer/customerList" >
	<!-- frozenStartColumn="0" frozenEndColumn="3" -->
	<div property="columns">
		<div type="indexcolumn" headerAlign="center">编号</div>
		<div field="area" width="80" headerAlign="center" allowSort="true">所在区域</div>
		<div field="name" width="100" headerAlign="center" allowSort="true">昵称</div>
		<div field="synchronous" width="80" headerAlign="center" allowSort="true" align="center">积分商城同步</div>
		<div field="stopname" width="40" headerAlign="center" allowSort="true" align="center">类型</div>
		<div field="users" width="80" headerAlign="center" allowSort="true">客户序列号</div>
		<div field="level" width="40" headerAlign="center" allowSort="true">等级<input property="editor" class="mini-combobox" textField="name" valueField="name" data="JS.CONST[1]" allowInput="true" style="width:100%;" /></div>
		<div field="year_num" width="40" headerAlign="center" allowSort="true">合作年限<input property="editor" class="mini-textarea" emptyText="请输入备注" textField="name" valueField="name" allowInput="true" style="width:100%;" /></div>
		<div field="st_time" width="100" headerAlign="center" allowSort="true" dateFormat="yyyy-MM-dd">客户开始时间
<!--            <input property="editor" class="mini-datepicker" format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true"  textField="name" valueField="name" allowInput="true" style="width:100%;" />-->
        </div>
		<div header="顾客联系信息" headerAlign="center">
			<div property="columns">
				<div field="adders" width="130" headerAlign="center" allowSort="true">地址</div>
				<div field="mobile_phone" width="80" headerAlign="center">手机号</div>
				<div field="tel" width="110" headerAlign="center">座机号</div>
				<div field="email" width="110" headerAlign="center">邮箱</div>
			</div>
		</div>
<!--		<div field="remark" width="120" headerAlign="center">备注<input property="editor" class="mini-textarea" emptyText="请输入备注" style="width:100%;height:40px;"/></div>-->
<!--		<div field="updated" width="70" headerAlign="center" dateFormat="yyyy-MM-dd" allowSort="true">更新日期</div>-->
		<div name="action" width="100" headerAlign="center" align="center" renderer="onActionRenderer" cellStyle="padding:0;">操作</div>
	</div>
</div>
<script type="text/javascript">
mini.parse();
var urlDel = "/customer/customerDel";
var urlUpd = "/customer/customerUpd";
var grid = mini.get("grid1");
grid.load({types:1});

$("#search").click(function(){
	grid.load({types:1,user:mini.get("user").getValue(),area:mini.get("area").getValue(),name:mini.get("name").getValue()});
});

//行选择设定功能状态
grid.on("selectionchanged",function(e){
	var row = grid.getSelected();
	if (row != null) {
		if(row.synchronous=="未同步"){
			mini.get("buttonUp").enable();
		}else{
			mini.get("buttonUp").disable();
		}
	}
});

$("#buttonUp").click(function(){
	var row = grid.getSelected();
	if (row != null) {
		//parent.$.dooDialog.confirm("你确定要把这个顾客同步到积分商城吗？",function(){
			$.post('/customer/synchronous',{id:row.sid},function(data){
				if(data.code=='OK'){
					parent.$.dooDialog.alert('顾客同步成功！');
					grid.load({types:1,user:mini.get("user").getValue(),area:mini.get("area").getValue(),name:mini.get("name").getValue()});
				}else{
					parent.$.dooDialog.alert('顾客同步失败，可能已经存在同名客户！');
					return false;
				}
			},'json');
		//});
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
});

$("#buttonStart").click(function(){
	var row = grid.getSelected();
	if (row != null) {
		parent.$.dooDialog.confirm("你确定要启用这个顾客吗？",function(){
			$.post('/customer/stopStart',{id:row.sid},function(data){
				if(data.code=='OK'){
					grid.load({types:1,user:mini.get("user").getValue(),area:mini.get("area").getValue(),name:mini.get("name").getValue()});
				}else{
					parent.$.dooDialog.alert('启用顾客失败！');
					return false;
				}
			},'json');
		});
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
});

$("#buttonEnd").click(function(){
	var row = grid.getSelected();
	if (row != null) {
		parent.$.dooDialog.confirm("你确定要禁用这个顾客吗？",function(){
			$.post('/customer/stopEnd',{id:row.sid},function(data){
				if(data.code=='OK'){
					grid.load({types:1,user:mini.get("user").getValue(),area:mini.get("area").getValue(),name:mini.get("name").getValue()});
				}else{
					parent.$.dooDialog.alert('禁用顾客失败！');
					return false;
				}
			},'json');
		});
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
});

$("#buttonReload").click(function(){
	var row = grid.getSelected();
	if (row != null) {
		parent.$.dooDialog.confirm("你确定要重置这个顾客的密码吗？",function(){
			$.post('/customer/pwdReload',{id:row.sid},function(data){
				if(data.code=='OK'){
					grid.load({types:1,user:mini.get("user").getValue(),area:mini.get("area").getValue(),name:mini.get("name").getValue()});
					parent.$.dooDialog.alert('密码重置成功！');
				}else{
					parent.$.dooDialog.alert('密码重置失败！');
					return false;
				}
			},'json');
		});
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
});

$("#buttonDown").click(function(){
	var row = grid.getSelected();
	if (row != null) {
		parent.$.dooDialog.confirm("你确定要客户降级为潜在客户吗？",function(){
			$.post('/customer/typesDown',{id:row.cid},function(data){
				if(data.code=='OK'){
					grid.load({types:1,user:mini.get("user").getValue(),area:mini.get("area").getValue(),name:mini.get("name").getValue()});
				}else{
					parent.$.dooDialog.alert('客户降级为潜在客户失败！');
					return false;
				}
			},'json');
		});
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
});
function onKeyEnter(e) {
	grid.load({types:1,user:mini.get("user").getValue(),area:mini.get("area").getValue(),name:mini.get("name").getValue()});
}
</script>